#include "stm32f4xx.h"
#include "nrf24l01p/nRF24L01P_dl.h"

#define LENGTH		256
uint8_t tx_buffer[LENGTH];
int temp = 1;

void loopt() {
//	uint8_t res = TxPacket(tx_buffer, LENGTH, 0x02);
//
////	if(temp == 1){
////		TxBroadcast_nRF24L01P(tx_buffer, 11);
////		temp = 0;
////		printf("Indirizzo cambiato!!\n");
////	}
//
////	printf("Address: %d\n", getTxAddress_nRF24L01P());
//
//	if (res == SUCCESS){
//		printf("Pacchetto Unicast Inviato!!\n");
//	}
//	else if(res == FRAME_LOST){
//		printf("Frame Lost!!\n");
//	}
//	else if (res == LENGTH_ERROR){
//		printf("Length non corretta, maggiore di 1920 byte!!\n");
//	}
	TxFrame_nRF24L01P(tx_buffer, 12);
	nRF24L01_Delay_us(500000);
	TxBroadcast_nRF24L01P(tx_buffer, 16);
	nRF24L01_Delay_us(500000);
////	uint8_t addr[5];
////	nRF24L01_get_tx_addr(addr);
////	printf("Indirizzo: %d\n", addr[0]);

//	TxBroadcast_nRF24L01P(tx_buffer, 20);
//	printf("Pacchetto Broadcast Inviato!!\n");
//	nRF24L01_Delay_us(500000);
}

int main() {
	int j = 0;
	setup_nRF24L01P();
	RxMode_nRF24L01P();
	for(; j <= LENGTH; j++){
		tx_buffer[j] = (j + 1) % 256;
		printf("%d ", tx_buffer[j]);
		if( (j + 1) % 32 == 0 ){
			printf("\n");
		}
	}
	printf("\n");

	tx_buffer[0] = 0x0c;
	tx_buffer[LENGTH - 1] = 0x0c;

	printf("main\n");

	while (1) {
		loopt();
		//RxPacket(tx_buffer, 0x03);
		toggleLeds(LED[1]);
	}
}

